﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace 多协议通信平台.Common
{
    public class Type2String : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is Type type)
            {
                return type.Name;
            }
            return "";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Type type = null;
            if (value is string valStr)
            {
                
                switch (valStr)
                {
                    case "Boolean": type = typeof(byte); break;
                    case "Int16": type = typeof(short); break;
                    case "UInt16": type= typeof(ushort); break;
                    case "Int32": type = typeof(int); break;
                    case "Single": type = typeof(float); break;
                    case "Int64": type = typeof(long); break;
                    default:
                        break;
                }
            }
            return type;
        }
    }
}
